/*
 * Top module cpp file of hana.
 * Created by Hardware Architecture Render Engine (HARE)
 * Version: 0.0.1 
 */
#include "op_dispatcher.h"
#include "main_memory.h"
#include "hana.h"


#include "hana_top.h"

DesignUnitTest::DesignUnitTest() :
    TopModule()
{
    int mem_cas_letency = 2;
    int mem_elements = 8388608;
    int multiplexer = 32;

    int sm_size = 128 * 4;

    QString filepath = "E:/Documents/PHD/ANU/hareru/examples/hana/programs/opcf/opcf.juna";
    bool visual = true;

    // Construct nodes.
    OpDispatcher *op_dispatcher = new OpDispatcher(this, filepath, visual);
    MainMemory *main_memory = new MainMemory(this, mem_cas_letency, multiplexer, mem_elements);
    NodeHanaParam param;
    param.multiplexer = multiplexer;
    param.peer_id_base = 0;
    param.num_of_peer_group = 4;
    param.num_of_peer = 4;
    param.softmem_size = sm_size;
    param.num_of_main_memory = 1;
    param.num_of_alu = 4;
    param.total_peers = 16;
    param.base_ptrs = List<int>();
    int base_ptr = 0;
    for(int i=0; i<4; ++i)
    {
        param.base_ptrs.append(base_ptr);
        base_ptr += 128;
    }
    NodeHana *chip = new NodeHana(this, param);

    // Preload the main memory.
    main_memory->preload(op_dispatcher->getAops());

    // Connect ports.
    ChannelTranOpFabric::connect(op_dispatcher->top_sender,
                                 chip->port_top_receiver);
    ChannelExecOpFabric::connect(op_dispatcher->eop_sender,
                                 chip->port_eop_receiver);
    ChannelLoadReqFabric::connect(chip->port_memory_requester[0], main_memory->request_receiver);
    ChannelLoadFabric::connect(main_memory->load_sender, chip->port_memory_receivers[0]);
    ChannelStoreFabric::connect(chip->port_memory_senders[0], main_memory->store_receiver);
}
